package com.ellecity06.cwhiskymall.adapter

import android.content.Context
import android.graphics.Color
import android.provider.CalendarContract.Colors
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.text.buildSpannedString
import androidx.core.text.scale
import com.chad.library.adapter.base.BaseQuickAdapter
import com.ellecity06.common.ktx.load
import com.ellecity06.common.ktx.prefixUnit
import com.ellecity06.common.viewholder.ViewBindingHolder
import com.ellecity06.cwhiskymall.R
import com.ellecity06.cwhiskymall.bean.response.AppMenuSettingRespone
import com.ellecity06.cwhiskymall.databinding.ItemHomeCategoryBinding
import com.ellecity06.cwhiskymall.databinding.ItemNewerGoodBinding
import com.ellecity06.cwhiskymall.databinding.ItemSelfGoodBinding
import com.ellecity06.cwhiskymall.storage.UserStorage

/**
 * @author ellecity06
 * @time 2024/10/23 13:33
 * @des 自营商品列表适配器
 */
class SelfGoodAdapter :
    BaseQuickAdapter<AppMenuSettingRespone.SettingWebLayoutVOS.GoodsVO, ViewBindingHolder<ItemSelfGoodBinding>>() {
    private val mWidth: Int by lazy { recyclerView.measuredWidth }
    override fun onBindViewHolder(
        holder: ViewBindingHolder<ItemSelfGoodBinding>,
        position: Int,
        item: AppMenuSettingRespone.SettingWebLayoutVOS.GoodsVO?
    ) {
        holder.binding.ivGood.load(context, item?.spuImage)
        holder.binding.tvGoodName.text = item?.spuName
        holder.binding.tvGiftPrice.visibility = UserStorage.upVisible()
        holder.binding.tvGiftPrice.text = buildSpannedString {
            scale(0.7F) {
                append("赠送")
            }
            append("${item?.contribution}")
            scale(0.7F) {
                append("贡献金")
            }
        }
        holder.binding.tvPrice.text = "￥${item?.salesPrice}"
        val p = position +1
        when{
            p %3==0->{
               holder.binding.rootContent.setBackgroundResource(R.drawable.shape_round_white_br_r10)
           }
            p %2==0->{
                holder.binding.rootContent.setBackgroundColor(Color.WHITE)
            }
            else ->{

                holder.binding.rootContent.setBackgroundResource(R.drawable.shape_round_white_bl_r10)
            }
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): ViewBindingHolder<ItemSelfGoodBinding> {
        val view = ItemSelfGoodBinding.inflate(LayoutInflater.from(context), parent, false)
//        //每个item平分整个屏幕的宽度
//        val params = view.root.layoutParams
//        params.width = mWidth / 4
        return ViewBindingHolder(view)
    }

}